package message.controller;

import junit.framework.Assert;
import message.types.data.AddDataRequest;
import message.types.none.GetLastDataRequest;
import message.types.stalker.RegisterRequest;

import org.junit.Test;

import stalker.room.PrivatePersistentRoom;
import stalker.room.Room;
import stalker.user.User;
import data.Data;
import data.content.Content;
import data.content.ContentSentence;

/**
 * JUnit test for visitors and controllers
 * @deprecated moved
 */

public class UserRoomCommunicationTest {
  
  User irvan;
  Room ruang;
  Content test;
  
  @Test
  public void testAddDataRequest() throws InterruptedException {
    irvan = User.createUser("Irvan");
    ruang = PrivatePersistentRoom.create("4031");
    test = new ContentSentence("It's raining, so I can't go");
    //send message
    irvan.acceptMessage(new AddDataRequest(irvan, ruang, test));
    Thread.sleep(100);
    //test if message is received successfully
    Assert.assertTrue("AddDataRequest fails", ruang.getDatas().isEmpty());
    
    irvan.acceptMessage(new RegisterRequest(irvan, ruang));
    Thread.sleep(100);
    
    irvan.acceptMessage(new AddDataRequest(irvan, ruang, test));
    Thread.sleep(100);
    //test if message is received successfully
    // Assert.assertTrue("AddDataRequest fails", ruang.getDatas().size() == 1);
    Data last = ruang.getDatas().retrieveLatestData();
    Assert.assertTrue("AddDataRequest fails", last.getCreator().equals(irvan));
    Assert.assertTrue("AddDataRequest fails", last.getContent().equals(test));
  }
  
  @Test
  public void testGetLastDataNotAuthorized() throws InterruptedException {
    User siska = User.createUser("Siska");
    ruang = Room.getRoomFromName("4031");
    siska.acceptMessage(new GetLastDataRequest(siska, ruang));
  }
  
  @Test
  public void testGetLastDataAuthorized() throws InterruptedException {
    irvan = User.getUserFromName("Irvan");
    ruang = Room.getRoomFromName("4031");
    irvan.acceptMessage(new GetLastDataRequest(irvan, ruang));
  }
  
}
